package com.goldsprite.gameframeworks.utils.math;

import java.util.HashMap;
import java.util.Map;

public class Axis {
	public enum Align { LeftUp, LeftDown, RightDown, RightUp, Center }


	public static Vector2 Bound_LDAxis = new Vector2(0, 1);
	public static Vector2 Bound_CenterAxis = new Vector2(-0.5f, 0.5f);

	public static Vector2 Pivot_LDAxis_Center = Vector2.Half();
	public static Vector2 Pivot_LDAxis_LeftDown = Vector2.Zero();
	public static Vector2 Pivot_LDAxis_RightDown = Vector2.Right();
	public static Vector2 Pivot_LDAxis_RightUp = Vector2.One();
	public static Vector2 Pivot_LDAxis_LeftUp = Vector2.Up();

	public static Vector2 Pivot_CenterAxis_Center = Vector2.Zero();
	public static Vector2 Pivot_CenterAxis_LeftDown = Vector2.LeftDown().scl(0.5f);
	public static Vector2 Pivot_CenterAxis_RightDown = Vector2.RightDown().scl(0.5f);
	public static Vector2 Pivot_CenterAxis_RightUp = Vector2.RightUp().scl(0.5f);
	public static Vector2 Pivot_CenterAxis_LeftUp = Vector2.LeftUp().scl(0.5f);

	//这里只添加两种常用坐标系，左下对齐坐标系和中心对齐坐标系
	private static Map<Align, Map<Align, Vector2>> pivotMap = new HashMap<Align, Map<Align, Vector2>>(){
		{
			put(Align.LeftDown,
				new HashMap<Align, Vector2>(){{
						put(Align.LeftDown, Pivot_LDAxis_LeftDown);
						put(Align.RightDown, Pivot_LDAxis_RightDown);
						put(Align.RightUp, Pivot_LDAxis_RightUp);
						put(Align.LeftUp, Pivot_LDAxis_LeftUp);
						put(Align.Center, Pivot_LDAxis_Center);
					}
				}
			);
			put(Align.Center,
				new HashMap<Align, Vector2>(){{
						put(Align.LeftDown, Pivot_CenterAxis_LeftDown);
						put(Align.RightDown, Pivot_CenterAxis_RightDown);
						put(Align.RightUp, Pivot_CenterAxis_RightUp);
						put(Align.LeftUp, Pivot_CenterAxis_LeftUp);
						put(Align.Center, Pivot_CenterAxis_Center);
					}
				}
			);
		}
	};
	private static Map<Align, Vector2> boundMap = new HashMap<Align, Vector2>(){
		{
			put(Align.LeftDown, Bound_LDAxis);
			put(Align.Center, Bound_CenterAxis);
		}
	};
	public static Vector2 getAxisAlignVector(Align axis, Align align) {
		return pivotMap.get(axis).get(align);
	}
	public static Vector2 getAxisBound(Align axis) {
		return boundMap.get(axis);
	}
	static float[] tempAlginCoord = new float[2];
	public static float[] getAlignCoord(Align axis, Align align, float x, float y, float width, float height) {
		Vector2 axisAlignVector = getAxisAlignVector(axis, align);
		tempAlginCoord[0] = x - width * axisAlignVector.x;
		tempAlginCoord[1] = y - height * axisAlignVector.y;
		return tempAlginCoord;
	}
}
